﻿/*======================================================================
== Copyright : BlueCurve (c)
== Licence   : Gnu/GPL v2.x
== Author    : Teddy Albina
== Email     : bluecurveteam@gmail.com
== Web site  : http://www.codeplex.com/BlueCurve
========================================================================*/
using System.Collections.Generic;
using System.Runtime.Serialization;

namespace BlueCurve.SearchContract
{
    /// <summary>
    /// Enumére les types de requêtes possibles
    /// </summary>
    [DataContract]
    public enum TypeOfRequest
    {
        /// <summary>
        /// Requête simple
        /// </summary>
        [EnumMember]
        Simple = 0x01,
        /// <summary>
        /// Requête avancé
        /// </summary>
        [EnumMember]
        Advanced = 0x02
    }

    /// <summary>
    /// Enumère les "critères" d'exclusion de mots
    /// </summary>
    [DataContract]
    public enum BooleanClause
    {
        /// <summary>
        /// BooleanClause.Occur.MUST Use this operator for clauses that must appear in the matching documents.
        /// </summary>
        [EnumMember]
        Must = 0x01,
        /// <summary>
        /// BooleanClause.Occur.MUST_NOT Use this operator for clauses that must not appear in the matching documents.
        /// </summary>
        [EnumMember]
        Must_Not = 0x02,
        /// <summary>
        /// BooleanClause.Occur.SHOULD Use this operator for clauses that should appear in the matching documents.
        /// </summary>
        [EnumMember]
        Should = 0x03
    }
    
    /// <summary>
    /// Définit une requête
    /// </summary>
    [DataContract]
    public class SearchQuery
    {
        /// <summary>
        /// Requête de l'utilisateur
        /// </summary>
        [DataMember(EmitDefaultValue=true)]
        public string Query { get; set; }
        /// <summary>
        /// Nombre de documents à afficher par page
        /// </summary>
        [DataMember(EmitDefaultValue=true)]
        public int MaxResponsePerPage { get; set; }
        /// <summary>
        /// Index de page demandé pour avancer ou reculer dans la recherche
        /// </summary>
        [DataMember]
        public int NeedPageIndex { get; set; }
        /// <summary>
        /// Type de requête 
        /// </summary>
        [DataMember]
        public TypeOfRequest TypeOfQuery = TypeOfRequest.Simple;
        /// <summary>
        /// Mots excluts
        /// (aucun des mots suivants)
        /// mot => type de présence
        /// <example>
        /// <![CDATA[Dictionary<word, KeyValuePair<field, BooleanClause>>]]>
        /// </example>
        /// </summary>
        [DataMember]
        public Dictionary<string, KeyValuePair<string, BooleanClause>> QueryFilter = new Dictionary<string, KeyValuePair<string, BooleanClause>>();
        /// <summary>
        /// Permets de savoir si certains type de contenus doivent etre filtrés
        /// </summary>
        [DataMember(EmitDefaultValue=true)]
        public bool SafeSearch { get; set; }
    }
}
